//
//  MBTabBarController.m
//  mibaotu
//
//  Created by 彭康 on 16/9/14.
//  Copyright © 2016年 pegnk. All rights reserved.
//

#import "MBTabBarController.h"
#import "MBStoryController.h"
#import "MBSpaceController.h"
#import "MBOnlineController.h"
#import "MBShowController.h"
#import "MBNavController.h"
#import "MBForumViewController.h"

#import "MBShowForIpadController.h"

@interface MBTabBarController ()

@end

@implementation MBTabBarController

- (void)viewDidLoad{
    
    [super viewDidLoad];
    
    // 1.初始化子控制器
    
    MBSpaceController *spaceVC = [[MBSpaceController alloc]init];
    [self addChildVC:spaceVC title:@"米宝空间" image:@"mibaokongjian1" selectedImage:@"mibaokongjian2"];
    
    
    MBStoryController*storyVC = [[MBStoryController alloc] init];
    [self addChildVC:storyVC title:@"故事库" image:@"gushiku1" selectedImage:@"gushiku2"];
    
    if (ISIPAD) {
        NSLog(@"i am a ipad!");
        MBShowForIpadController*showVC=[[MBShowForIpadController alloc]init];
       [self addChildVC:showVC title:@"亲子秀场" image:@"qinzixiuchang1" selectedImage:@"qinzixiuchang2"];
       
      

    }else{
    MBShowController *showVC = [[MBShowController alloc]init];
        [self addChildVC:showVC title:@"亲子秀场" image:@"qinzixiuchang1" selectedImage:@"qinzixiuchang2"];

    }
    
    MBForumViewController *forum = [[MBForumViewController alloc]init];
    [self addChildVC:forum title:@"论坛" image:@"luntan1" selectedImage:@"luntan2"];
    
    
    MBOnlineController *onlineVC = [[MBOnlineController alloc]init];
    [self addChildVC:onlineVC title:@"在线电台" image:@"zaixiandiantai1" selectedImage:@"zaixiandiantai2"];
    //默认选择第二个控制器
    self.selectedIndex = 1;
    
}

/**
 *  添加子控制器
 */
- (void)addChildVC:(UIViewController *)childVC title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage{
    
    childVC.title = title;
    
    childVC.tabBarItem.image = [UIImage imageNamed:image];
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置文字样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    textAttrs[NSForegroundColorAttributeName] = [UIColor colorWithRed:141/255.0f green:141/255.0f blue:141/255.0f alpha:1.0f];
    
    NSMutableDictionary *seleTextAttrs = [NSMutableDictionary dictionary];
    seleTextAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    
    seleTextAttrs[NSForegroundColorAttributeName] = TINK_BG_COLOR;
    
    [childVC.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [childVC.tabBarItem setTitleTextAttributes:seleTextAttrs forState:UIControlStateSelected];
    
    MBNavController *nav = [[MBNavController alloc]initWithRootViewController:childVC];
    
    
    [self addChildViewController:nav];
    
    
    
    
    
}
- (BOOL)shouldAutorotate
{
    return [self.selectedViewController shouldAutorotate];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return [self.selectedViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}



@end
